Component({
  properties: {
    // 这里定义了innerText属性，属性值可以在组件使用时指定
    date: {
      type: null
    }
  },
  data: {
    day: 0,
    hour: 0,
    minute: 0,
    second: 0,
    timer: null,
    olddate: ''
  },
  ready: function () {
    this.CaculateDate();
    var newtdate = this.data.date.replace(/-/g, '/')
    this.setData({ olddate: new Date(newtdate) })
  },
  detached: function () {
    if (this.data.timer) {
      clearInterval(this.data.timer)
    }

  },
  methods: {
    // 这里是一个自定义方法
    CaculateDate: function () {
      var that = this;
      var timerID = setInterval(function () {
        var tdate = new Date(that.data.olddate);
        var now = new Date();
        tdate.setSeconds(tdate.getSeconds() - 1);
        var leftTime = tdate - new Date(); //计算剩余的毫秒数 
        var days = parseInt(leftTime / 1000 / 60 / 60 / 24, 10); //计算剩余的天数 
        var hours = parseInt(leftTime / 1000 / 60 / 60 % 24, 10); //计算剩余的小时 
        var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟 
        var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数 
        if (leftTime > 0) {
          that.setData({ olddate: tdate })
          that.setData({ day: days, hour: hours, minute: minutes, second: seconds })
        }
      }, 1000)
      this.setData({ timer: timerID })
    }
  }
})